package cz.muni.fi.pa165.library.backend;

import java.util.List;
import javax.persistence.EntityManager;

/**
 * DAO interface of Reservation. Searching methods return object or null if
 * object is not stored.
 *
 * @author Marián Labuda
 * @version 1.4
 */
public interface ReservationDAO {

    /**
     * Set entity manager. Useful for mocking tests.
     *
     * @param entityManager
     */
    void setEntityManager(EntityManager entityManager);

    /**
     * Delete reservation.
     *
     * @param reservation Reservation to be deleted.
     * @throws IllegalArgumentException when reservation is null or reservation
     * doesn't have ID or reservation doesn't exist
     */
    boolean deleteReservation(Reservation reservation);

    /**
     * Find all reservations of books.
     *
     * @return List of all reservations
     */
    List<Reservation> findAllReservations();

    /**
     * Find reservation containing given book.
     *
     * @param book
     * @return Reservation containing given book or null if doesn't exist
     * @throws IllegalArgumentException when book is null or doesn't have ID
     */
    Reservation findReservationByBook(Book book);

    /**
     * Find reservation with given ID.
     *
     * @param id ID of reservation
     * @return Reservation with given ID or null if doesn't exist
     * @throws IllegalArgumentException when id is null or lesser than or equals
     * to 0
     */
    Reservation findReservationByID(Long id);

    /**
     * Find all reservations of given reader.
     *
     * @param reader
     * @return List of all reader's reservations or empty list if reader doesn't
     * have any reservation
     * @throws IllegalArgumentException when reader is null or doesn't have ID
     */
    List<Reservation> findReservationsByReader(Reader reader);
    
    /**
     * Principal mode of inserting reservation. If reservation is already stored
     * then nothing happens. Reservation can't have null attributes (except ID).
     *
     * @param reservation Reservation to be inserted
     * @throws IllegalArgumentException when reservation is null or already has
     * set ID or book is not available
     */
    Reservation insertReservation(Reservation reservation);
}
